{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-02-11T03:39:43.005299Z",
     "start_time": "2025-02-11T03:39:42.521352Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "list2 = [[1, 2], [3, 4], [5, 6]]\n",
    "\n",
    "twoArray = np.array(list2)\n",
    "# 获取数组的维度( 注意： 与函数的参数很像) \n",
    "print(twoArray.ndim)\n",
    "\n",
    "# 形状（行，列） (0 axis,1 axis)\n",
    "print(twoArray.shape)\n",
    "\n",
    "# 有多少个元素\n",
    "print(twoArray.size)\n",
    "# 数据类型\n",
    "print(twoArray.dtype)  #默认int32,4个字节，数据范围 -21亿到21亿"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "(3, 2)\n",
      "6\n",
      "int64\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T03:40:41.030390Z",
     "start_time": "2025-02-11T03:40:41.026865Z"
    }
   },
   "cell_type": "code",
   "source": [
    "four = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "\n",
    "print(four)\n",
    "# 修改的是原有的\n",
    "four1 = four\n",
    "print(id(four))"
   ],
   "id": "74bcc3cf98f54f2b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "2680057198608\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T03:40:57.670287Z",
     "start_time": "2025-02-11T03:40:57.666834Z"
    }
   },
   "cell_type": "code",
   "source": [
    "four.shape = (3, 2)  # 改变形状\n",
    "print(id(four))\n",
    "print(id(four1))\n",
    "print(four)"
   ],
   "id": "2c1ea0d94370783f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2680057198608\n",
      "2680057198608\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T03:42:25.039580Z",
     "start_time": "2025-02-11T03:42:25.033834Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('-' * 50)\n",
    "# 返回一个新的数组，reshape后id和之前的不一样\n",
    "four2 = four.reshape(2, 3)\n",
    "print(four)\n",
    "print(four2)\n",
    "print(id(four))\n",
    "print(id(four2))\n",
    "four2"
   ],
   "id": "a238985fe1572b09",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "[[1 2]\n",
      " [3 4]\n",
      " [5 6]]\n",
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "2680057198608\n",
      "2680057881168\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:07:15.133470Z",
     "start_time": "2025-02-11T04:07:15.129845Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 将多维变成一维数组\n",
    "five = four.reshape((6,), order='C')\n",
    "# five = four.reshape(6, 1)\n",
    "# 默认情况下‘C’以行为主的顺序展开，‘F’（Fortran风格）意味着以列的顺序展开\n",
    "six = four.flatten()  # 展开成一维数组\n",
    "print(five)\n",
    "print('-' * 50)\n",
    "print(six)\n",
    "\n",
    "# print(five.reshape(3,2))"
   ],
   "id": "c4e42b756649efd3",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4 5 6]\n",
      "--------------------------------------------------\n",
      "[1 2 3 4 5 6]\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:09:00.814472Z",
     "start_time": "2025-02-11T04:09:00.809578Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print('-' * 50)\n",
    "# 拓展：数组的形状\n",
    "t = np.arange(24)  #和列表的range函数一样，生成一个数组\n",
    "print(t)\n",
    "print(f'shape{t.shape}')\n",
    "print(t.ndim)\n",
    "# 转换成二维\n",
    "t1 = t.reshape((4, 6))\n",
    "print(t1)\n",
    "print(t1.shape)"
   ],
   "id": "cb56688d8af5394f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]\n",
      "shape(24,)\n",
      "1\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "(4, 6)\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:09:30.662901Z",
     "start_time": "2025-02-11T04:09:30.659051Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 转成三维\n",
    "#最前面的是零轴，轴越小，越靠外，最小的轴是最外层\n",
    "# 0轴，1轴，2轴\n",
    "t2 = t.reshape((2, 3, 4))\n",
    "print(t2)\n",
    "print(t2.shape)\n",
    "print(t2.ndim)"
   ],
   "id": "d817b9f1269acd0d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0  1  2  3]\n",
      "  [ 4  5  6  7]\n",
      "  [ 8  9 10 11]]\n",
      "\n",
      " [[12 13 14 15]\n",
      "  [16 17 18 19]\n",
      "  [20 21 22 23]]]\n",
      "(2, 3, 4)\n",
      "3\n"
     ]
    }
   ],
   "execution_count": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:09:50.965788Z",
     "start_time": "2025-02-11T04:09:50.961587Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t3 = t.reshape((2, 3, 2, 2))\n",
    "print(t3)\n",
    "print(t3.shape)\n",
    "print(t3.ndim)"
   ],
   "id": "cc8a7c07263d4f0c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[[ 0  1]\n",
      "   [ 2  3]]\n",
      "\n",
      "  [[ 4  5]\n",
      "   [ 6  7]]\n",
      "\n",
      "  [[ 8  9]\n",
      "   [10 11]]]\n",
      "\n",
      "\n",
      " [[[12 13]\n",
      "   [14 15]]\n",
      "\n",
      "  [[16 17]\n",
      "   [18 19]]\n",
      "\n",
      "  [[20 21]\n",
      "   [22 23]]]]\n",
      "(2, 3, 2, 2)\n",
      "4\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "NumPy的数据类型",
   "id": "6b954ce8fc7bd267"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:10:35.695212Z",
     "start_time": "2025-02-11T04:10:35.692003Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import random\n",
    "\n",
    "f = np.array([1, 2, 3, 4, 127], dtype=np.int8)  # 返回数组中每个元素的字节单位长度,dtype设置数据类型\n",
    "print(f.itemsize)  # 1 np.int16(一个字节)\n",
    "# 获取数据类型\n",
    "print(f.dtype)"
   ],
   "id": "b1f53ffd6f98f260",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "int8\n"
     ]
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T04:13:19.556662Z",
     "start_time": "2025-02-11T04:13:19.552142Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 调整数据类型\n",
    "f1 = f.astype(np.int64)\n",
    "print(f1.dtype)\n",
    "print(f1.itemsize)  #显示字节数\n",
    "print('-' * 50)"
   ],
   "id": "16d9c75c59d0e805",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int64\n",
      "8\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": " 数组和数的计算",
   "id": "1d5f01f4e829c457"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:12:33.249138Z",
     "start_time": "2025-02-11T06:12:33.241735Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 由于numpy的广播机机制在运算过程中，加减乘除的值被广播到所有的元素上面\n",
    "t1 = np.arange(24).reshape((6, 4))\n",
    "print(t1)\n",
    "print(\"-\" * 20)\n",
    "t2 = t1.tolist()\n",
    "print(t1 + 2)\n",
    "# print(t2+2) 不能对列表进行直接加整数操作\n",
    "print(\"-\" * 20)\n",
    "print(t1 * 2)\n",
    "print(\"-\" * 20)\n",
    "print(t1 / 2)\n",
    "\n",
    "#无论多少维的ndarray都可以直接和一个常数进行运算"
   ],
   "id": "15f67a48c99c3e7c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]\n",
      " [12 13 14 15]\n",
      " [16 17 18 19]\n",
      " [20 21 22 23]]\n",
      "--------------------\n",
      "[[ 2  3  4  5]\n",
      " [ 6  7  8  9]\n",
      " [10 11 12 13]\n",
      " [14 15 16 17]\n",
      " [18 19 20 21]\n",
      " [22 23 24 25]]\n",
      "--------------------\n",
      "[[ 0  2  4  6]\n",
      " [ 8 10 12 14]\n",
      " [16 18 20 22]\n",
      " [24 26 28 30]\n",
      " [32 34 36 38]\n",
      " [40 42 44 46]]\n",
      "--------------------\n",
      "[[ 0.   0.5  1.   1.5]\n",
      " [ 2.   2.5  3.   3.5]\n",
      " [ 4.   4.5  5.   5.5]\n",
      " [ 6.   6.5  7.   7.5]\n",
      " [ 8.   8.5  9.   9.5]\n",
      " [10.  10.5 11.  11.5]]\n"
     ]
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:13:06.664410Z",
     "start_time": "2025-02-11T06:13:06.659688Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#形状相同,才可以进行加减乘除\n",
    "t1 = np.arange(24).reshape((6, 4))\n",
    "t2 = np.arange(100, 124).reshape((6, 4))\n",
    "print(t1)\n",
    "print(t2)\n",
    "print('-' * 50)\n",
    "print(t1 + t2)\n",
    "print('-' * 50)\n",
    "print(t1 * t2)  #是否是矩阵乘法？不是\n"
   ],
   "id": "db05dd10efeebdb",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]\n",
      " [12 13 14 15]\n",
      " [16 17 18 19]\n",
      " [20 21 22 23]]\n",
      "[[100 101 102 103]\n",
      " [104 105 106 107]\n",
      " [108 109 110 111]\n",
      " [112 113 114 115]\n",
      " [116 117 118 119]\n",
      " [120 121 122 123]]\n",
      "--------------------------------------------------\n",
      "[[100 102 104 106]\n",
      " [108 110 112 114]\n",
      " [116 118 120 122]\n",
      " [124 126 128 130]\n",
      " [132 134 136 138]\n",
      " [140 142 144 146]]\n",
      "--------------------------------------------------\n",
      "[[   0  101  204  309]\n",
      " [ 416  525  636  749]\n",
      " [ 864  981 1100 1221]\n",
      " [1344 1469 1596 1725]\n",
      " [1856 1989 2124 2261]\n",
      " [2400 2541 2684 2829]]\n"
     ]
    }
   ],
   "execution_count": 25
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:13:21.580555Z",
     "start_time": "2025-02-11T06:13:21.566917Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#shape不同，不能进行运算\n",
    "t1 = np.arange(24).reshape((4, 6))\n",
    "t2 = np.arange(6).reshape((3, 6))\n",
    "print(t1)\n",
    "print(t2)\n",
    "print(t1 - t2)"
   ],
   "id": "401bd1c61af2069d",
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "cannot reshape array of size 6 into shape (3,6)",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[26], line 3\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;66;03m#shape不同，不能进行运算\u001B[39;00m\n\u001B[0;32m      2\u001B[0m t1 \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39marange(\u001B[38;5;241m24\u001B[39m)\u001B[38;5;241m.\u001B[39mreshape((\u001B[38;5;241m4\u001B[39m, \u001B[38;5;241m6\u001B[39m))\n\u001B[1;32m----> 3\u001B[0m t2 \u001B[38;5;241m=\u001B[39m \u001B[43mnp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43marange\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m6\u001B[39;49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mreshape\u001B[49m\u001B[43m(\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;241;43m3\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m6\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m      4\u001B[0m \u001B[38;5;28mprint\u001B[39m(t1)\n\u001B[0;32m      5\u001B[0m \u001B[38;5;28mprint\u001B[39m(t2)\n",
      "\u001B[1;31mValueError\u001B[0m: cannot reshape array of size 6 into shape (3,6)"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:13:30.241733Z",
     "start_time": "2025-02-11T06:13:30.235179Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#一维数组和二维数组进行运算时，一维的元素个数和列数相等\n",
    "t1 = np.arange(24).reshape((4, 6))\n",
    "t2 = np.arange(6).reshape((1, 6))\n",
    "print(t2.shape)\n",
    "print(t1)\n",
    "print(t2)\n",
    "t1 - t2\n"
   ],
   "id": "19f61051ed206058",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 6)\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "[[0 1 2 3 4 5]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0,  0,  0,  0,  0,  0],\n",
       "       [ 6,  6,  6,  6,  6,  6],\n",
       "       [12, 12, 12, 12, 12, 12],\n",
       "       [18, 18, 18, 18, 18, 18]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:14:06.094296Z",
     "start_time": "2025-02-11T06:14:06.089060Z"
    }
   },
   "cell_type": "code",
   "source": [
    "t1 = np.arange(24).reshape((4, 6))\n",
    "t2 = np.arange(4).reshape((4, 1))\n",
    "print(t2)\n",
    "print(t1)\n",
    "t1 - t2\n"
   ],
   "id": "b878ed0b5b74b382",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0]\n",
      " [1]\n",
      " [2]\n",
      " [3]]\n",
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [ 5,  6,  7,  8,  9, 10],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [15, 16, 17, 18, 19, 20]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 28
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:34:07.777971Z",
     "start_time": "2025-02-11T06:34:07.773349Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#随机3维数组\n",
    "a = np.arange(24).reshape((2, 3, 4))\n",
    "b = np.arange(12).reshape((1, 3, 4))\n",
    "a - b"
   ],
   "id": "b037c16303741933",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  0,  0,  0],\n",
       "        [ 0,  0,  0,  0],\n",
       "        [ 0,  0,  0,  0]],\n",
       "\n",
       "       [[12, 12, 12, 12],\n",
       "        [12, 12, 12, 12],\n",
       "        [12, 12, 12, 12]]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 30
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:34:22.701344Z",
     "start_time": "2025-02-11T06:34:22.696562Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "print(a)\n",
    "print(\"-\" * 20)\n",
    "print(np.sum(a, axis=0))  # [5 7 9]，按哪个轴求和，哪个轴没了\n",
    "print(\"-\" * 20)\n",
    "print(np.sum(a, axis=1))  # [ 6 15]\n",
    "print(\"-\" * 20)\n",
    "print(np.sum(a))\n",
    "print(\"-\" * 20)\n"
   ],
   "id": "18474528124c7758",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n",
      "--------------------\n",
      "[5 7 9]\n",
      "--------------------\n",
      "[ 6 15]\n",
      "--------------------\n",
      "21\n",
      "--------------------\n"
     ]
    }
   ],
   "execution_count": 31
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:34:55.177619Z",
     "start_time": "2025-02-11T06:34:55.173123Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a = np.arange(24).reshape((2, 3, 4))\n",
    "b = np.sum(a, axis=0)\n",
    "print(\"-\" * 20)\n",
    "print(b.shape)\n",
    "c = np.sum(a, axis=1)\n",
    "print(\"-\" * 20)\n",
    "print(c.shape)\n",
    "d = np.sum(a, axis=2)\n",
    "print(\"-\" * 20)\n",
    "print(d.shape)"
   ],
   "id": "baa07222969b9a03",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "(3, 4)\n",
      "--------------------\n",
      "(2, 4)\n",
      "--------------------\n",
      "(2, 3)\n"
     ]
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "索引和切片",
   "id": "c49324490b28999c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:35:28.733930Z",
     "start_time": "2025-02-11T06:35:28.729893Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(10)\n",
    "# 冒号分隔切片参数 start:stop:step 来进行切片操作print(a[2:7:2])# 从索引 2 开始到索引 7 停止，间隔为 2\n",
    "\n",
    "# 如果只放置一个参数，如 [2]，将返回与该索引相对应的单个元素\n",
    "print(a[0], a)\n",
    "\n",
    "# 如果为 [2:]，表示从该索引开始以后的所有项都将被提取\n",
    "print(a[2:])\n",
    "\n",
    "print(a[2:8:2])  #切片是左闭右开\n"
   ],
   "id": "a3956e38fd9caa6f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 [0 1 2 3 4 5 6 7 8 9]\n",
      "[2 3 4 5 6 7 8 9]\n",
      "[2 4 6]\n"
     ]
    }
   ],
   "execution_count": 33
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-02-11T06:35:38.641957Z",
     "start_time": "2025-02-11T06:35:38.636709Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import numpy as np\n",
    "\n",
    "t1 = np.arange(24).reshape(4, 6)\n",
    "print(t1)\n",
    "print('*' * 20)\n",
    "print(t1[1])  # 取一行(一行代表是一条数据，索引也是从0开始的) print(t1[1,:]) # 取一行\n",
    "print('*' * 20)\n",
    "print(t1[1:])  # 取连续的多行\n",
    "print('*' * 20)\n",
    "print(t1[1:3, :])  # 取连续的多行\n",
    "print('*' * 20)\n",
    "print(t1[[0, 2, 3]])  # 取不连续的多行"
   ],
   "id": "39012ad64bce50cc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "********************\n",
      "[ 6  7  8  9 10 11]\n",
      "********************\n",
      "[[ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n",
      "********************\n",
      "[[ 6  7  8  9 10 11]\n",
      " [12 13 14 15 16 17]]\n",
      "********************\n",
      "[[ 0  1  2  3  4  5]\n",
      " [12 13 14 15 16 17]\n",
      " [18 19 20 21 22 23]]\n"
     ]
    }
   ],
   "execution_count": 34
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "print(t1[:, 1])  # 取一列\n",
    "print('*' * 20)\n",
    "print(t1[:, 1:])  # 连续的多列\n",
    "print('*' * 20)\n",
    "print(t1[:, [0, 2, 3]])  # 取不连续的多列\n",
    "print('*' * 20)\n",
    "print(t1[2, 3])  # # 取某一个值,三行四列  py是t1[2][3]\n",
    "print('*' * 20)\n",
    "print(t1[[0, 1, 1], [0, 1, 3]])  # 取多个不连续的值，[[行，行。。。],[列，列。。。]]\n",
    "\n",
    "t1[1:3, 1:4]  #取1-3行，1-4列"
   ],
   "id": "bf094eba227080d1"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
